using System.ComponentModel.DataAnnotations;

namespace ConsoleApp1;

public abstract class Shape
{   
    protected double area;
    public string name;
    public abstract double GetArea();
    public abstract bool IsRight();
}

class Circle:Shape
{
    private double radius { set; get; }
    
    public Circle(double radius,string name)
    {
        Console.WriteLine("创建圆");
        this.radius = radius;
        this.name = name;
    }
    public override double GetArea()
    {
        area = radius * radius * Math.PI;
        return area;
    }
    
    public override bool IsRight()
    {
        if (this.radius > 0) return true;
        return false;
    }
}

class Rectangle : Shape
{ 
    private double length { set; get; }
    private double width { set; get; }
    
    public Rectangle(double length,double width,string name)
    {
        Console.WriteLine("创建长方形");
        this.length = length;
        this.width = width;
        this.name = name;
    }
    public override double GetArea()
    {
        area = this.length * this.width;
        return area;
    }
    
    public override bool IsRight()
    {
        if (length>0&&width>0) return true;
        return false;
    }
}

class Square:Shape
{
    private double Lengthening { set; get; }
    
    public Square(double Lengthening,string name)
    {
        Console.WriteLine("创建正方形");
        this.Lengthening = Lengthening;
        this.name = name;
    }
    public override double GetArea()
    {
        area = Lengthening * Lengthening;
        return area;
    }
    
    public override bool IsRight()
    {
        if (Lengthening>0) return true;
        return false;
    }
}

class Caller
{
    public double GetArea(Shape shape)
    {
        double area = shape.GetArea();
        return area;
    }

    public bool IsRight(Shape shape)
    {
        if (shape.IsRight())
        {
            Console.WriteLine("{0}是合法的",shape.name);
            return true;
        }
        else
        {
            Console.WriteLine("{0}不是合法的",shape.name);
            return false;
        }
    }
}

class Test
{
    static void Main(string[] args)
    {
        Caller c = new Caller();
        List<Shape> list = new List<Shape>();
        Random random = new Random();
        double sumArea=0;
        for (int i = 0; i < 10; i++)
        {
            int count = random.Next(0, 3);//生成0-2的随机数
            switch (count)
            {
                case 0:
                    double radius = 100*random.NextDouble();
                    Shape shape1 = new Circle(radius,"圆");
                    while (!c.IsRight(shape1))
                    {
                        double radius1 = 100*random.NextDouble();
                        Shape shape11 = new Circle(radius,"圆");
                    }
                    sumArea += c.GetArea(shape1);
                    break;
                case 1:
                    double length = 100*(random.NextDouble()+0.01);
                    double width = 100*(random.NextDouble()+0.01);
                    Shape shape2 = new Rectangle(length,width,"长方形");
                    while (!c.IsRight(shape2))
                    {
                        double length1 = 100*(random.NextDouble()+0.01);
                        double width1 = 100*(random.NextDouble()+0.01);
                        Shape shape22 = new Rectangle(length,width,"长方形");
                    }
                    sumArea += c.GetArea(shape2);
                    break;
                case 2:
                    double lengthning = 100*(random.NextDouble()+0.01);
                    Shape shape3 = new Square(lengthning,"正方形");
                    while (!c.IsRight(shape3))
                    {
                        double lengthning1 = 100*(random.NextDouble()+0.01);
                        Shape shape33 = new Square(lengthning,"正方形");
                    }
                    sumArea += c.GetArea(shape3);
                    break;
            }
        }
        Console.WriteLine("所有形状面积之和为{0}",sumArea);
    }
}